package fourFragment;

import oneFragment.OneFragment;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.sangdaelee.example.kakaoproject.R;

public class FourFragment extends Fragment {
	
	TextView tv;
	TextView tv2;
	EditText et , et2;
	Button btn1,btn2;
	
	SharedPreferences sharedPref;
	SharedPreferences.Editor sharedEditor;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View v = inflater.inflate(R.layout.preference_activity, container, false);
		tv = (TextView)v.findViewById(R.id.idText);
		tv2 = (TextView)v.findViewById(R.id.pwText);
		et = (EditText)v.findViewById(R.id.idinput);
		et2 = (EditText)v.findViewById(R.id.pwInput);
		btn1 = (Button)v.findViewById(R.id.idadd);
		btn2 = (Button)v.findViewById(R.id.cancelBtn);
		
		sharedPref = getActivity().getSharedPreferences("pref", getActivity().MODE_PRIVATE);
		sharedEditor = sharedPref.edit();
		
		btn1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String id = et.getText().toString();
				String pw = et2.getText().toString();
				sharedEditor.putString("id", id);
				sharedEditor.putString("pw", pw);
				
				sharedEditor.commit();
				Toast.makeText(v.getContext(), "login", Toast.LENGTH_SHORT).show();
				et.setEnabled(false);
				et2.setEnabled(false);
			}
		});
		btn2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				et.setText("");
				et2.setText("");
				sharedEditor.putString("id", "");
				sharedEditor.putString("pw", "");
				
				sharedEditor.commit();
				Toast.makeText(v.getContext(), "canced", Toast.LENGTH_SHORT).show();
				et.setEnabled(true);
				et2.setEnabled(true);
			}
		});
		
		return v;
	}
	
	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		String id = sharedPref.getString("id", "");
		String pw = sharedPref.getString("pw", "");
		
		et.setText(String.valueOf(id));
		et2.setText(String.valueOf(pw));
	}

}
